<div class="wrapper">
    <div>
        <div class="box box-top">
            <!-- /.box-header -->
            <!-- form start -->
            <form id="riderForm" role="form" action="${base}/admin/rider/save" method="post">
                <input type="hidden" name="id" value="${(rider.id?c)!}">
                <div class="box-body">
                    <div class="form-group">
                        <label for="carNo">手机号</label>
                        ${(rider.phone)!''}
                    </div>
                    <div class="form-group">
                        <label for="level">区域</label>
                        <select name="departmentId" id="departmentId" class="form-control">
                            <#list departmentList as t>
                                <option value="${t.id}" <#if ((rider.departmentId)!0)==t.id> selected="selected"</#if>>----${t.name}----</option>
                            </#list>

                        </select>
                    </div>
                    <div class="form-group">
                        <label for="level">身份信用</label>
                        <select name="level" id="level" class="form-control">
                            <option value="0" <#if ((rider.level)!0)==0> selected="selected"</#if>>----身份证抵押----</option>
                            <option value="1" <#if ((rider.level)!0)==1> selected="selected"</#if>>----现金抵押----</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label for="state">激活Status(押金Status)</label>
                        <select name="state" id="state" class="form-control">
                            <option value="0" <#if ((rider.state)!0)==0> selected="selected"</#if>>----未激活----</option>
                            <option value="1" <#if ((rider.state)!0)==1> selected="selected"</#if>>----已激活----</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label for="rentType">租用类型</label>
                        <select name="rentType" id="rentType" class="form-control">
                        <option value="">----请选择租用类型----</option>
                            <#list rentTypeList as t>
                                <option value="${t.id}" <#if (rider.rentType!0)==t.id>selected="selected"</#if>>${t.name}</option>
                            </#list>
                        </select>
                    </div>
                    <div class="form-group">
                        <label for="name">姓名</label>
                        <input type="text" value="${(rider.name)!''}" class="form-control" id="name" name="name" >
                    </div>
                    <div class="form-group">
                        <label for="expirDate">过期日期:例如 2020-02-02 10位</label>
                        <input type="text" value="${nav.getDate((rider.endDate)!'')}" class="form-control" id="expirDate" name="expirDate" >
                    </div>
                    <div class="form-group">
                        <label for="expirDate">激活过期日期:例如 2020-02-02 10位</label>
                        <input type="text" value="${nav.getDate((rider.jhDate)!'')}" class="form-control" id="expirJhDate" name="expirJhDate" >
                    </div>
                    <div class="form-group">
                        <label for="carNo">微信Id（非特殊情况请不要修改）</label>
                        <input type="text" value="${(rider.unionid)!''}" class="form-control" id="unionid" name="unionid" >
                    </div>
                    <div class="form-group">
                        <label for="carNo">车架号</label>
                        <input type="text" value="${(rider.carNo)!''}" class="form-control" id="carNo" name="carNo" >
                    </div>

                    <div class="form-group">
                        <label for="spareName">备用联系人</label>
                        <input type="text" value="${(rider.spareName)!''}" class="form-control" id="spareName" name="spareName" >
                    </div>
 <div class="form-group">
                        <label for="spareName">备用联系方式</label>
                        <input type="text" value="${(rider.sparePhone)!''}" class="form-control" id="sparePhone" name="sparePhone" >
                    </div>
<div class="form-group">
                        <label for="memo">Note</label>
                        <input type="text" value="${(rider.memo)!''}" class="form-control" id="memo" name="memo" >
                    </div>
                    <div class="form-group">
                        <label for="exampleInputFile">附件</label>
                        <div class="row">

                            <div class="col-xs-2" style="width: 12%;">
                                <input type="file" id="exampleInputFile" multiple="multiple">
                            </div>
                            <div class="col-xs-2">
                                <input type="button" value="上传" onclick="pushImg()">
                            </div>
                        </div>
                        <input type="hidden" id="annex" name="annex" value="${(rider.annex)!''}">
                        <p class="help-block"><a href="${(rider.annex)!''}" target="_blank">附件下载</a></p>
                    </div>
                    <div class="box-footer">
                        <button type="button" onclick="$('#riderForm').submit();" class="btn btn-primary">Save
                        </button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(function() {
        $("#riderForm").validate({
            submitHandler:function(form){
                submitRider();
            }
        });
    });
    function submitRider(){
        HF.ajaxFormSubmit('riderForm',function(result){
            alert("Save Success");
            document.location.reload();
        },function(e){ alert("Save Failure");});
    }
    function pushImg(obj) {

        var url = '${base}'+ "/admin/rider/titleImgeUpload"; //访问控制器是upload，后面必须加'/'否则会报错"org.apache.catalina.connector.RequestFacade cannot be cast to org.springframework.web.multipart.Mult...",但是如果是多级的URL【例如XX/XXX/00/upload/0】又没问题了.
        var files = $("#exampleInputFile").get(0).files[0]; //获取file控件中的内容

        var fd = new FormData();
        fd.append("uploadFile", files);
        $.ajax({
            type: "POST",
            contentType:false, //必须false才会避开jQuery对 formdata 的默认处理 , XMLHttpRequest会对 formdata 进行正确的处理
            processData: false, //必须false才会自动加上正确的Content-Type
            url: url,
            data: fd,
            success: function (msg) {

                var obj = eval('(' + JSON.stringify(msg) + ')');
                if(obj.SUCESS){
                    //填充图片
                    $("#titleImage").attr("src", obj.DATA);
                    $("#titleImage").css("width","150");
                    $("#titleImage").css("height","100");
                    //写入隐藏域
                    $("#annex").val(obj.DATA);
                }
            },
            error: function (msg) {
                //debugger;
                alert("error");
            }
        });
    }
</script>
